package com.gcmm.context;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class AppContext implements ApplicationContextAware
{

    private ConfigurableApplicationContext context;

    public void exit()
    {
        if (null != context)
        {
            context.close();
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
    {
        if (applicationContext instanceof ConfigurableApplicationContext) {
            this.context =  (ConfigurableApplicationContext) applicationContext;
        }

    }
}
